package com.magicode.screen.react.activity;

import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.facebook.react.ReactActivityDelegate;
import com.facebook.react.ReactRootView;
import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
import com.magicode.screen.AppContext;
import com.magicode.screen.AppManager;
import com.magicode.screen.react.util.SplashScreen;

import javax.annotation.Nullable;

/**
 * MainTab界面
 * 
 * @author kymjs (http://www.kymjs.com/)
 */
public class MainTabReactActivity extends MgcReactActivity implements DefaultHardwareBackBtnHandler {
    private ReactRootView mReactRootView;
    private String userId = AppContext.getInstance().getLoginUid();
    private String activityName = "maintab";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // 添加Activity到堆栈
        AppManager.getAppManager().addActivity(this);
        //设置状态栏悬浮并全透明
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Window window = getWindow();
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(Color.TRANSPARENT);
        }

        SplashScreen.show(this);  // 添加这一句
        super.onCreate(savedInstanceState);

    }


    @Override
    protected String getMainComponentName() {
        return "maintab";
    }


//    protected @Nullable
//    Bundle getLaunchOptions() {
//        Bundle bundle=new Bundle();
//        bundle.putString("userId",userId);
//        bundle.putString("activityName",activityName);
//        bundle.putString("statusBarHeight", String.valueOf(this.getStatusBarHeight()));
//        bundle.putString("serverUrl", UIHelper.getServerUrl(this));
//        bundle.putString("login", login);
//        return bundle;
//    }

    public Bundle bundleOptions(){
        Bundle bundle=new Bundle();
//        bundle.putString("userId",userId);
        bundle.putString("activityName",activityName);
//        bundle.putString("statusBarHeight", String.valueOf(this.getStatusBarHeight()));
        return bundle;

    }
    @Override
    protected ReactActivityDelegate createReactActivityDelegate() {
        return new ReactActivityDelegate(this, getMainComponentName()) {
            @Nullable
            @Override
            protected Bundle getLaunchOptions() {
                Bundle bundle=bundleOptions();
                return bundle;
            }
        };
    }

    /**
     * 获取状态栏的高度
     * @return
     */
    public int getStatusBarHeight() {
        int result = 0;
        int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
        if (resourceId > 0) {
            result = getResources().getDimensionPixelSize(resourceId);
        }
        return result;
    }
    @Override
    public void onBackPressed() {
       super.onBackPressed();
    }
}
